package com.authine.cloudpivot.app.openapi.controller;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.extension.BizScenario;
import com.authine.cloudpivot.app.openapi.dto.DeleteGatewayCmd;
import com.authine.cloudpivot.app.openapi.dto.SaveGatewayRouteCmd;
import com.authine.cloudpivot.app.openapi.dto.domainmodel.GatewayRouteDefinition;
import com.authine.cloudpivot.app.openapi.feign.GatewayFeignServiceI;
import com.authine.cloudpivot.app.openapi.service.RouteServiceImpl;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lifuchun
 */
@RestController
public class RouteController implements GatewayFeignServiceI {

    private final RouteServiceImpl routeServiceImpl;

    public RouteController(RouteServiceImpl routeServiceImpl) {
        this.routeServiceImpl = routeServiceImpl;
    }


    @Override
    public Response add(@RequestBody GatewayRouteDefinition param) {

        SaveGatewayRouteCmd cmd = SaveGatewayRouteCmd.builder().route(param).build();
        cmd.setBizScenario(BizScenario.valueOf("gateway", "add", "springCloudGateway"));

        return routeServiceImpl.add(cmd);
    }

    @Override
    public Response delete(@PathVariable("id") String id) {
        DeleteGatewayCmd cmd = new DeleteGatewayCmd(id);
        cmd.setBizScenario(BizScenario.valueOf("gateway", "delete", "springCloudGateway"));
        return routeServiceImpl.delete(cmd);
    }


    @Override
    public Response update(@RequestBody GatewayRouteDefinition param) {
        SaveGatewayRouteCmd cmd = new SaveGatewayRouteCmd(param);

        cmd.setBizScenario(BizScenario.valueOf("gateway", "update", "springCloudGateway"));
        return routeServiceImpl.update(cmd);
    }


}